import re

if __name__ == '__main__':
    with open('htmlsample.html', 'r', encoding='UTF-8') as handler:
        lineList = handler.readlines()

    tag = re.compile('<[^<>]+>')
    blank = re.compile('^[\s]\s*')

    for i in range(len(lineList)):
        lineList[i] = tag.sub('', lineList[i])
        lineList[i] = blank.sub('', lineList[i])

    with open('htmlsample_new.txt', 'w', encoding='UTF-8') as handler:
        handler.writelines(lineList)
